/*The MIT License

Copyright (c) <2008> <Samir Menon>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/


#ifndef CDCAKNANEURON_H_
#define CDCAKNANEURON_H_

#include "CSynCaKNaNeuron.h"

namespace bis_neuron
{
	using namespace std;
		
	#define KIR2_A 0.0
	#define KIR2_B 1.0
	#define KIR2_C 1.5
	#define KIR2_DOWN 0.5
	#define KIR2_MED 0.2
	#define KIR2_UP 0.2
	#define VM_BISTABLE 1.5
	#define POTENTIATED_DA_SYNAPSE_STRENGTH 0.5
	#define NON_POTENTIATED_DA_SYNAPSE_STRENGTH 0.3
	#define DEFAULT_NUM_DA_STDP_SYNAPSES 20

	class CDCaKNaNeuron : public bis_neuron::CSynCaKNaNeuron
	{	
	protected:
	//		Inherited: 
	//		int neuron_id;
	//		float vm, v_na;
	//		float vm_max,vm_min;
	//		float r;
	//		int execution_flag;
	//		bool log_data_flag, log_spike_flag;
	//		CSpikeSpooler *data_spooler, *spike_spooler;
	//		stringstream data_log_stream;
	//		CSystemClock* clock;	
	//		float sigma,n;
	//		float g_k,tau_k,delta_gk;
	//		NEURON_CLOCK t_last_spike;
	//		float i_ca, i_ca_hold, tau_ca, r_ca, delta_i_ca;
	//		CSynapse* stdp_synapse;
	//		unsigned int num_synapses;
			CSynapse* da_synapse;
			unsigned int num_da_synapses;
			float g_k_kir2;
			
			inline float return_gk_kir2();
			inline bool update_vm();
		
	public:
	
		CDCaKNaNeuron(const int & arg_num_da_synapses = DEFAULT_NUM_DA_STDP_SYNAPSES, 
									const int &  arg_num_stdp_synapses = DEFAULT_NUM_STDP_SYNAPSES);
		CDCaKNaNeuron(const float & arg_tau_ca, const float & arg_i_ca_max, 
									const unsigned int & arg_num_da_synapses,  
								 const unsigned int & arg_stdp_synapses, 
								 const float & arg_delta_i_ca, const float & arg_r_ca,
								 const float & arg_tau_k, const float & arg_delta_gk,
								 const float & arg_sigma, const float & arg_n);
		virtual ~CDCaKNaNeuron();
		
				//Inherited Synapse Functions:
//				void activate_stdp_synapse(unsigned int arg_stdp_syn_id);
//				void set_stdp_synapse(const unsigned int & arg_stdp_syn_id, 
//													const unsigned int & arg_neuron_from,
//						const float & arg_pot_syn_strength = POTENTIATED_SYNAPSE_STRENGTH, 
//						const float & arg_non_pot_syn_strength = NON_POTENTIATED_SYNAPSE_STRENGTH);		
	
	//Synapse
	void activate_da_synapse(const unsigned int & arg_da_syn_id);	
	
	void set_da_synapse(const unsigned int & argda_syn_id, 
													const unsigned int & arg_neuron_from,
						const float & arg_pot_syn_strength = POTENTIATED_DA_SYNAPSE_STRENGTH, 
						const float & arg_non_pot_syn_strength = NON_POTENTIATED_DA_SYNAPSE_STRENGTH);
	
	bool fire();	
	//		void update_vm_burst();//Uses supra-threshold membrane voltage reset for bursting
	void reset_neuron();
	void set_data(const float & arg_r, const float & arg_sigma, 
											 const float & arg_n, const float & arg_tau_k,
											 const float & arg_delta_gk,
											 const float & arg_tau_ca, const float & arg_r_ca, 
											 const float & arg_delta_i_ca);	
	void log_data();	
	//	Inherited:
	//	CKNaNeuron();
	//	CKNaNeuron(float arg_tau_k, float arg_delta_gk, float arg_sigma = DEFAULT_Na_SIGMA, 
	//			float arg_n = DEFAULT_Na_N);
	//	CNaNeuron();
	//	CNaNeuron(float arg_sigma, float arg_n);
	//	~CNaNeuron();	
	//	//Implemented virtual functions:
	//	void initialize(int neuron_id, float arg_ip_curr =DEFAULT_IP_CURR, 
	//			CSpikeSpooler * arg_spike_spool=NULL, CSpikeSpooler * arg_data_spool = NULL);	 
	//	void fire();
	
	//		Logging functions:
	//		void set_data_logging(CSpikeSpooler* arg_data_spool);
	//		void log_data(); //Basic: vm,neuron_id - Each neuron class should extend this		
	//		inline void set_data_log_flag_on() { log_data_flag=true;}
	//		inline void set_data_log_flag_off() { log_data_flag=false;}
	//		inline bool get_data_log_flag() { return log_data_flag;}
	//		
	//		void set_spike_logging(CSpikeSpooler* arg_spike_spool);
	//		void log_spike();		
	//		inline void set_spike_log_flag_on() { log_spike_flag=true;}
	//		inline void set_spike_log_flag_off() { log_spike_flag=false;}
	//		inline bool get_spike_log_flag() { return log_spike_flag;}
	//		//Wrappers:
	//		inline void set_exec_flag_on() { execution_flag=1;}
	//		inline void set_exec_flag_off() { execution_flag=0;}
	//		inline int get_exec_flag() { return execution_flag;}	
	};

}

#endif /*CDCAKNANEURON_H_*/
